package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DateTypeEnum;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.TransferEnum;
import com.xbongbong.saas.enums.dictionary.TransferNewStatusEnum;
import com.xbongbong.saas.enums.dictionary.TransferStatusEnum;
import com.xbongbong.saas.enums.dictionary.TransferTypeEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.sys.enums.RoleEnum;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import lombok.Getter;
import java.util.Objects;

/**
 * @author Jian.Wang
 * @version v1.0
 * @date 2019/1/29 20:27
 * @since v1.0
 */
@Getter
public enum TempTransferEnum {
    //
    BASE_INFO(TransferEnum.BASE_INFO),
    SHEET_NO(TransferEnum.SHEET_NO),
    TRANSFER_STATUS(TransferEnum.TRANSFER_STATUS),
    TRANSFER_TYPE(TransferEnum.TRANSFER_TYPE),
    OUT_WAREHOUSE_ID(TransferEnum.OUT_WAREHOUSE_ID),
    INTO_WAREHOUSE_ID(TransferEnum.INTO_WAREHOUSE_ID),
    MANAGER_NAME(TransferEnum.MANAGER_NAME),
    TRANSFER_TIME(TransferEnum.TRANSFER_TIME),
    PRODUCTS(TransferEnum.PRODUCTS),
    MEMO(TransferEnum.MEMO),

    SYSTEM_INFO(TransferEnum.SYSTEM_INFO),
    CREATOR_ID(TransferEnum.CREATOR_ID),
    ADD_TIME(TransferEnum.ADD_TIME),
    UPDATE_TIME(TransferEnum.UPDATE_TIME),

    INSTOCK_ID(TransferEnum.INSTOCK_ID),
    OUTSTOCK_ID(TransferEnum.OUTSTOCK_ID),
    OUT_WAREHOUSE_ID_LINKED_TEXT(TransferEnum.OUT_WAREHOUSE_ID_LINKED_TEXT),
    INTO_WAREHOUSE_ID_LINKED_TEXT(TransferEnum.INTO_WAREHOUSE_ID_LINKED_TEXT),
    STATUS(TransferEnum.STATUS),
    ;

    private TransferEnum anEnum;

    TempTransferEnum(TransferEnum transferEnum) {
        this.anEnum = transferEnum;
    }

    public static List<TempTransferEnum> getAllEnum() {
        List<TempTransferEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    /**
     * 初始化调拨单流水号
     *
     * @param fieldAttrEntity 字段
     * @author feng.zheng
     * @date 2019/2/19 10:58
     */
    public static void initSheetNo(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.TRANSFER.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.TRANSFER.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(SHEET_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setSerialNumber(InitExplainsHelper.setSerialNumber(SerialNumberEnum.TRANSFER_NO));
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化调拨单流水号
     *
     * @param fieldAttrEntity 字段
     * @author feng.zheng
     * @date 2019/2/19 10:58
     */
    public static void initStatus(FieldAttrEntity fieldAttrEntity) {
//        List<ItemPoJo> itemPoJos = new ArrayList<>();
//        ItemPoJo itemPoJo1 = new ItemPoJo();
//        itemPoJo1.setText(TransferStatusEnum.WAIT_OUT_INSTOCK.getName());
//        itemPoJo1.setValue(TransferStatusEnum.WAIT_OUT_INSTOCK.getCode());
//        itemPoJos.add(itemPoJo1);
//        ItemPoJo itemPoJo2 = new ItemPoJo();
//        itemPoJo2.setText(TransferStatusEnum.ALREADY_OUT_INSTOCK.getName());
//        itemPoJo2.setValue(TransferStatusEnum.ALREADY_OUT_INSTOCK.getCode());
//        itemPoJos.add(itemPoJo2);
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(TransferStatusEnum.class, fieldAttrEntity.getFieldType()));
    }
    /**
     * 初始化产品
     *
     * @param fieldAttrEntity 实体
     */
    public static void initProducts(FieldAttrEntity fieldAttrEntity) {
//        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
//        saasParticularAttributePoJo.setRelyMode(XbbRefTypeEnum.WAREHOUSE.getAlias());
//        saasParticularAttributePoJo.setRelyType("relied");
//        saasParticularAttributePoJo.setRelySubModel(XbbRefTypeEnum.OUTSTOCK.getAlias());
//        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
        //由后端逻辑控制
//        fieldAttrEntity.setNoEditable(1);
    }

    /**
     * 初始化调出仓库
     *
     * @param fieldAttrEntity 字段
     * @author feng.zheng
     * @date 2019/2/19 10:44
     */
    public static void initOutWarehouseId(FieldAttrEntity fieldAttrEntity) {
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
//        saasParticularAttributePoJo.setRelyMode(XbbRefTypeEnum.WAREHOUSE.getAlias());
//        saasParticularAttributePoJo.setRelyType("base");
//        saasParticularAttributePoJo.setRelySubModel(XbbRefTypeEnum.OUTSTOCK.getAlias());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.WAREHOUSE.getCode());
        fieldAttrEntity.setLinkedText(OUT_WAREHOUSE_ID_LINKED_TEXT.anEnum.getAttr());
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化调入仓库
     *
     * @param fieldAttrEntity 字段
     * @author feng.zheng
     * @date 2019/2/19 10:44
     */
    public static void initIntoWarehouseId(FieldAttrEntity fieldAttrEntity) {
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.WAREHOUSE.getCode());
        fieldAttrEntity.setLinkedText(INTO_WAREHOUSE_ID_LINKED_TEXT.anEnum.getAttr());
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化调拨日期
     *
     * @param fieldAttrEntity 字段
     * @author feng.zheng
     * @date 2019/2/19 10:54
     */
    public static void initTransferTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType(DateTypeEnum.YMD.getAlias());
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initManagerName(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setMultiple(0);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setRequired(1);
        //可新增权限：默认【超级管理员、销售主管、、创建人、负责人、负责人主管】可新增负责人，支持自定义；
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.WAREHOUSE_MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.WAREHOUSE_MANAGER));
    }
    public static void initTransferStatus(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsDictionary(1);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setEditable(0);
        List<ItemPoJo> itemPoJos = InitExplainsHelper.setCombItemByEnum(TransferNewStatusEnum.class, fieldAttrEntity.getFieldType());
        List<String> shipStatusCodeList = Arrays.asList(TransferNewStatusEnum.UNTRANSFORMED.getName(), TransferNewStatusEnum.UNRECEIVED.getName(), TransferNewStatusEnum.DELIVERED.getName(), TransferNewStatusEnum.TRANSFERRED.getName(), TransferNewStatusEnum.CLOSED.getName());
        for (ItemPoJo itemPoJo: itemPoJos) {
            itemPoJo.setNoDel(1);
            itemPoJo.setNoEdit(1);
            if (!shipStatusCodeList.contains(itemPoJo.getText())) {
                itemPoJo.setShowType(ShowTypeEnum.NONE.getCode());
                itemPoJo.setEditHide(1);
            } else {
                if (Objects.equals(itemPoJo.getText(), TransferNewStatusEnum.UNTRANSFORMED.getName())) {
                    itemPoJo.setChecked(true);
                }
            }
        }
        List<String> settingList = Arrays.asList(ForbiddenSettingEnum.DISABLE_OPTION_RELY.getAlias(), ForbiddenSettingEnum.DISABLE_SELF_DEFINE.getAlias());
        fieldAttrEntity.setForbiddenSettingList(settingList);
        fieldAttrEntity.setItemBanDefault(1);
        fieldAttrEntity.setItems(itemPoJos);
    }
    public static void initTransferType(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsDictionary(1);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setAdvancedSetHide(1);
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(TransferTypeEnum.class, fieldAttrEntity.getFieldType()));
    }
}
